CFLAGS = -Wall -fpic -coverage -lm -std=c99 -O0

rngs.o: rngs.h rngs.c
        gcc -c rngs.c -g  $(CFLAGS)

dominion.o: dominion.h dominion.c rngs.o
        gcc -c dominion.c -g  $(CFLAGS)

playdom: dominion.o playdom.c
        gcc -o playdom playdom.c -g dominion.o rngs.o $(CFLAGS)

testDrawCard: testDrawCard.c dominion.o rngs.o
        gcc -o testDrawCard -g  testDrawCard.c dominion.o rngs.o $(CFLAGS)

badTestDrawCard: badTestDrawCard.c dominion.o rngs.o
        gcc -o badTestDrawCard -g  badTestDrawCard.c dominion.o rngs.o $(CFLAGS)

testBuyCard: testBuyCard.c dominion.o rngs.o
        gcc -o testBuyCard -g  testBuyCard.c dominion.o rngs.o $(CFLAGS)

testAll: dominion.o testSuite.c
        gcc -o testSuite testSuite.c -g  dominion.o rngs.o $(CFLAGS)

interface.o: interface.h interface.c
        gcc -c interface.c -g  $(CFLAGS)

player: player.c interface.o
        gcc -o player player.c -g  dominion.o rngs.o interface.o $(CFLAGS)
   
testutils.o: testutils.h testutils.c rngs.o
        gcc -c testutils.c rngs.o $(CFLAGS)

testdominion: testdominion.c dominion.o interface.o testutils.o
        gcc -o testdominion testdominion.c -g dominion.o rngs.o interface.o testutils.o $(CFLAGS)

unittest1: unittest1.c dominion.o rngs.o
        gcc -o unittest1 -g unittest1.c dominion.o rngs.o $(CFLAGS)

unittest2: unittest2.c dominion.o rngs.o
        gcc -o unittest2 -g unittest2.c dominion.o rngs.o $(CFLAGS)
    
unittest3: unittest3.c dominion.o rngs.o
        gcc -o unittest3 -g unittest3.c dominion.o rngs.o $(CFLAGS)
    
unittest4: unittest4.c dominion.o rngs.o
        gcc -o unittest4 -g unittest4.c dominion.o rngs.o $(CFLAGS)

cardtest1: cardtest1.c dominion.o rngs.o
        gcc -o cardtest1 -g cardtest1.c dominion.o rngs.o $(CFLAGS)

cardtest2: cardtest2.c dominion.o rngs.o
        gcc -o cardtest2 -g cardtest2.c dominion.o rngs.o $(CFLAGS)

cardtest3: cardtest3.c dominion.o rngs.o
        gcc -o cardtest3 -g cardtest3.c dominion.o rngs.o $(CFLAGS)

cardtest4: cardtest4.c dominion.o rngs.o
        gcc -o cardtest4 -g cardtest4.c dominion.o rngs.o $(CFLAGS)
    
randomtestadventurer: randomtestadventurer.c dominion.o rngs.o testutils.o
        gcc -o randomtestadventurer -g randomtestadventurer.c dominion.o rngs.o testutils.o $(CFLAGS)

randomtestcard: randomtestcard.c dominion.o rngs.o testutils.o
        gcc -o randomtestcard -g randomtestcard.c dominion.o rngs.o testutils.o $(CFLAGS)
        
unittestresults.out: unittest1 unittest2 unittest3 unittest4 cardtest1 cardtest2 cardtest3 cardtest4 runtests

randomtestadventurer.out: randomtestadventurer
        rm -f randomtestadventurer.out
        randomtestadventurer >> randomtestadventurer.out
        gcov dominion -b >> randomtestadventurer.out

randomtestcard.out: randomtestcard
        rm -f randomtestcard.out
        randomtestcard >> randomtestcard.out
        gcov dominion -b >> randomtestcard.out

runtests:
        rm -f unittestresults.out
        cardtest1 >> unittestresults.out
        cardtest2 >> unittestresults.out
        cardtest3 >> unittestresults.out
        cardtest4 >> unittestresults.out
        unittest1 >> unittestresults.out
        unittest2 >> unittestresults.out
        unittest3 >> unittestresults.out
#omitting due to segfault - see coverage.txt 
#unittest4 >> unittresults.out
        gcov cardtest1 -b >> unittestresults.out
        gcov cardtest2 -b >> unittestresults.out
        gcov cardtest3 -b >> unitesttresults.out
        gcov cardtest4 -b >> unittestresults.out
        gcov unittest1 -b >> unittestresults.out
        gcov unittest2 -b >> unittestresults.out
        gcov unittest3 -b >> unittestresults.out
#gcov unittest4 -b >> unittestresults.out
        gcov dominion -b >> unittestresults.out

        deps = testutils.c dominion.c rngs.c

projunittests.out: ambassador_test.c cutpurse_test.c embargo_test.c outpost_test.c salvager_test.c seahag_test.c steward_test.c treasure_map_test.c tribute_test.c
	echo "Results for Team 17 unit tests:" >> projunittests.out
	echo "Ambassador effect test:" >> projunittests.out
	gcc -o ambassador_test ambassador_test.c $(deps) $(CFLAGS)
	ambassador_test >> projunittests.out
	gcov -b dominion.c >> projunittests.out

	echo "Cutpurse effect test:" >> projunittests.out
	gcc -o cutpurse_test cutpurse_test.c $(deps) $(CFLAGS)
	cutpurse_test >> projunittests.out
	gcov -b dominion.c >> projunittests.out

	echo "embargo effect test:" >> projunittests.out
	gcc -o embargo_test embargo_test.c $(deps) $(CFLAGS)
	embargo_test >> projunittests.out
	gcov -b dominion.c >> projunittests.out

	echo "outpost effect test:" >> projunittests.out
	gcc -o outpost_test outpost_test.c $(deps) $(CFLAGS)
	outpost_test >> projunittests.out
	gcov -b dominion.c >> projunittests.out

	echo "salvager effect test:" >> projunittests.out
	gcc -o salvager_test salvager_test.c $(deps) $(CFLAGS)
	salvager_test >> projunittests.out
	gcov -b dominion.c >> projunittests.out

	echo "seahag effect test:" >> projunittests.out
	gcc -o seahag_test seahag_test.c $(deps) $(CFLAGS)
	seahag_test >> projunittests.out
	gcov -b dominion.c >> projunittests.out

	echo "steward effect test:" >> projunittests.out
	gcc -o steward_test steward_test.c $(deps) $(CFLAGS)
	steward_test >> projunittests.out
	gcov -b dominion.c >> projunittests.out

	echo "treasure map effect test:" >> projunittests.out
	gcc -o treasure_map_test treasure_map_test.c $(deps) $(CFLAGS)
	treasure_map_test >> projunittests.out
	gcov -b dominion.c >> projunittests.out

	echo "tribute effect test:" >> projunittests.out
	gcc -o tribute_test tribute_test.c $(deps) $(CFLAGS)
	tribute_test >> projunittests.out
	gcov -b dominion.c >> projunittests.out

testdominion.out: testdominion
        rm -f testdominion.out
        testdominion >> testdominion.out

council_room: council_room_test.c
	gcc -o council_room_test -g council_room_test.c dominion.o rngs.o testutils.o $(CFLAGS)

feast: feast_test.c
	gcc -o feast_test -g feast_test.c dominion.o rngs.o testutils.o $(CFLAGS)

mine: mine_test.c
	gcc -o mine -g mine_test.c dominion.o rngs.o testutils.o $(CFLAGS)

remodel: remodel_test.c
	gcc -o remodel -g remodel_test.c dominion.o rngs.o testutils.o $(CFLAGS)

smithy: smithy_test.c
	gcc -o smithy -g smithy_test.c dominion.o rngs.o testutils.o $(CFLAGS)

village: village_test.c
	gcc -o village -g village_test.c dominion.o rngs.o testutils.o $(CFLAGS)

baron: baron_test.c
	gcc -o baron -g baron_test.c dominion.o rngs.o testutils.o $(CFLAGS)

great_hall: great_hall_test.c
	gcc -o great_hall -g great_hall_test.c dominion.o rngs.o testutils.o $(CFLAGS)

minion: minion_test.c
	gcc -o minion -g minion_test.c dominion.o rngs.o testutils.o $(CFLAGS)

all: playdom player testDrawCard testBuyCard badTestDrawCard unittest1 unittest2 unittest3 unittest4 cardtest1 cardtest2 cardtest3 cardtest4 randomtestadventurer randomtestcard testdominion testdominion.out council_room feast mine smithy remodel village baron great_hall minion projunittest.out

clean:
        rm -f *.o playdom.exe playdom test.exe test player player.exe testDrawCard testDrawCard.exe testBuyCard testBuyCard.exe badTestDrawCard badTestDrawCard.exe unittest1 unittest2 unittest3 unittest4 cardtest1 cardtest2 cardtest3 cardtest4 randomtestadventurer randomtestcard testdominion *.gcov *.gcda *.gcno *.so unittestresults.out gameResults.out testdominion.out council_room feast mine remodel baron minion steward tribute ambassador cutpurse embargo outpost salvager sea_hag treasure_map